package com.linkhub.oms.dao.mpservice.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkhub.oms.common.enums.mp.DataStatusEnum;
import com.linkhub.oms.dao.mapper.ExchangeRateEntityMapper;
import com.linkhub.oms.dao.mpservice.IExchangeRateService;
import com.linkhub.oms.entity.ExchangeRateEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 汇率表 服务实现类
 * </p>
 *
 * @author Frank
 * @since 2024-06-08
 */
@Service
@Slf4j
public class ExchangeRateServiceImpl extends ServiceImpl<ExchangeRateEntityMapper, ExchangeRateEntity> implements IExchangeRateService {


    @Override
    public List<ExchangeRateEntity> listExchangeRate(LocalDate date) {
        return super.lambdaQuery()
                .select(ExchangeRateEntity::getId,
                        ExchangeRateEntity::getExchangeRate)
                .eq(Objects.nonNull(date), ExchangeRateEntity::getRateDate, date)
                .eq(ExchangeRateEntity::getDataStatus, DataStatusEnum.ENABLE)
                .orderByDesc(ExchangeRateEntity::getId)
                .last("limit 10")
                .list();
    }

}
